import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import p12.P12Util;
import sun.security.x509.X509CertImpl;
import tls.RSAUtil;

import javax.crypto.Cipher;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class TEST3 {
    public static void main(String[] args) throws Exception {
        String encrypted="784e184491d12524d786be472390a0c846b26c8226837c999c6a4ef196d688c9963c9eb9118c81ca8bb5a51bc6c573efb988e3231a25a07833c3ee9052307e4192d4486f61f6e25ab621d49d89146ac99bdca3f649e26a61fc7edb1e392678ead76dbc1ff59bf58a8392c37d5c88a856966dc67d283a33e47302fe42e435e1e1e2960e7a59eab0a17f5f1a49e5a0cd4cb0d2b19dd060fe381d8ceeb2ed4f4776a6b57b1be7dd11cc13c4dd69588a64acf27abfaa4491d7ab419d8346d2395016220a9eeedbe8db5a51961e69f7e746fa7d5472153b27a5defc0c5f68439146b07e9e11e4829397d317dbcb6a795d144492e32bbc3290b174762af7e89daee304";


        String certificateStr="3082035d30820245a003020102020470815dde300d06092a864886f70d01010b0500305f310d300b0603550406130454455354310d300b0603550408130454455354310d300b0603550407130454455354310d300b060355040a130454455354310d300b060355040b13045445535431123010060355040313094855414e474a49414e301e170d3235303832353136333532335a170d3335303832333136333532335a305f310d300b0603550406130454455354310d300b0603550408130454455354310d300b0603550407130454455354310d300b060355040a130454455354310d300b060355040b13045445535431123010060355040313094855414e474a49414e30820122300d06092a864886f70d01010105000382010f003082010a02820101009996e8c5ede04d567edf1546c36e344526ec18b1490c4d6c5227d936dc19a139c7be6a0f65d4f130a128a5d65a7764cce3d38c1bffbfc1be6e9dfaa3a2a59ec99436114be3af56e5ebae674b2bc91aa47f9b32f606545f414e04af6ca3f869a596166c4c7c9764049eb57c903b1b1d32d5ff1ebdc85ad69736adac9a5a1c73e433565202efb514216b0488170b179f48d0a54cbb7f7762f5153a45f8bb1b113305a23338685b5a47a75c88767d430b45d8c0267c47ce2847ba1f1c7a7c2cfd640ba1d1cfa4525b539e4ec231a1ef5470e1f91c90935ea0553f3b408eebcef19d57fd2e4b72dad9075f1a5d25af04091fbbcaaac23edee4a9a108ed2fa07683570203010001a321301f301d0603551d0e04160414b670b984ea26b5457bf1fe65b2ab247f10e8d358300d06092a864886f70d01010b05000382010100784e184491d12524d786be472390a0c846b26c8226837c999c6a4ef196d688c9963c9eb9118c81ca8bb5a51bc6c573efb988e3231a25a07833c3ee9052307e4192d4486f61f6e25ab621d49d89146ac99bdca3f649e26a61fc7edb1e392678ead76dbc1ff59bf58a8392c37d5c88a856966dc67d283a33e47302fe42e435e1e1e2960e7a59eab0a17f5f1a49e5a0cd4cb0d2b19dd060fe381d8ceeb2ed4f4776a6b57b1be7dd11cc13c4dd69588a64acf27abfaa4491d7ab419d8346d2395016220a9eeedbe8db5a51961e69f7e746fa7d5472153b27a5defc0c5f68439146b07e9e11e4829397d317dbcb6a795d144492e32bbc3290b174762af7e89daee304";
        X509CertImpl cert=new X509CertImpl(Hex.decodeHex(certificateStr));

     //   String s = RSAUtil.decryptByHex(encrypted, P12Util.getPublicKey());
      //  System.out.println(s);



//        Cipher cipher = Cipher.getInstance("SHA256WithRSA");
//        cipher.init(Cipher.DECRYPT_MODE, P12Util.getPublicKey());
//        byte[] decryptedBytes =  cipher.doFinal(Hex.decodeHex(encrypted));
//        //cipher.doFinal(Base64.getDecoder().decode(encryptedText)); // 解码Base64字符串为字节数组
//        System.out.println(Hex.encodeHexString(decryptedBytes));


//
//        Signature sign=Signature.getInstance("SHA256withRSA");
//
//        sign.update();

        System.err.println(Hex.encodeHexString(RSAUtil.decrypt(encrypted,P12Util.getPublicKey())));

        System.out.println(Hex.encodeHexString(P12Util.getCertificate().getEncoded()));

        MessageDigest sha256 = MessageDigest.getInstance("SHA-256");

        ;

        System.out.println(Hex.encodeHexString(sha256.digest(RSAUtil.decrypt(encrypted,P12Util.getPublicKey()))));


    }
}
